package info.hexin.redis;

import org.springframework.data.redis.core.RedisTemplate;

import java.util.concurrent.TimeUnit;

/**
 * Created by infi.he on 2016/1/28.
 */
public class TestExpire extends AbstractRedisTest {
    public static void main(String[] args) {
        TestExpire test1 = new TestExpire();

        RedisTemplate redisTemplate = test1.getRedisTemplate();

        String key = "infi-test-001";
        redisTemplate.opsForValue().set(key, key, 10, TimeUnit.SECONDS);
        //这样会覆盖掉TTL，这个值永远都不会被删除
        redisTemplate.opsForValue().set(key, System.currentTimeMillis());
        System.out.println(System.currentTimeMillis()/1000);
        for (;;){
            try {
                if(redisTemplate.hasKey(key)){
                    Thread.sleep(1*1000);
                    System.out.println(System.currentTimeMillis()/1000);
                } else {
                    break;
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
